/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package py.com.spadons.esmetil.controllers.jsf.converters;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;
import py.com.spadons.esmetil.utils.Anho;
import py.com.spadons.esmetil.utils.Mes;

/**
 *
 * @author spadons
 */
@FacesConverter(forClass = Mes.class)
public class MesConverter implements Converter{
    
     @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        if (value == null || value.length() == 0) {
                return null;
            }
       
        return new Mes(value);
    }

    @Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {
        if (value == null) {
                return null;
            }
            if (value instanceof Mes) {
                Mes o = (Mes) value;
                return o.getMesString();
            } else {
                throw new IllegalArgumentException("object " + value + " is of type " + value.getClass().getName() + "; expected type: " + Mes.class.getName());
            }
    }
    
}
